package com.googlecode.likesql.converter;

import java.util.LinkedList;
import java.util.List;

import com.googlecode.likesql.constant.SqlChar;
import com.googlecode.likesql.constant.SqlConstant;

/**
 * This object is to convert character to a SQL string or template.
 * Quote(') will be replace as double quote('').
 * 
 * @author Johny Huang
 * @since 0.1
 */
public class CharConverter implements Converter {

	public String toTemplate(Object obj) {
		return String.valueOf(SqlConstant.CHAR_FOR_REPLACE);
	}

	public String toSql(Object obj) {
		Character ch=(Character)obj;
		String result=ch.toString();
		if(ch.charValue()=='\''){
			result+=SqlChar.QUOTE;
		}
		return SqlChar.QUOTE+result+SqlChar.QUOTE;
	}
	
	public List toValueList(Object obj) {
		LinkedList list=new LinkedList();
		list.add(obj.toString());
		return list;
	}

}
